/*
 * EventSupport.h
 *
 *  Created on: 2010-9-5
 *      Author: try
 */

#ifndef DEVENTDISPATCHER_H_
#define DEVENTDISPATCHER_H_

#include <event/Event.h>
#include <event/EventDispatcher.h>
#include "MouseEvent.h"
#include "WheelEvent.h"
#include "KeyEvent.h"
#include "SelectEvent.h"
#include "ModifiedEvent.h"
#include "PaintEvent.h"

namespace Ed {

  class EventSupport: public Thk::EventDispatcher {
    public:
      EventSupport(){};
      virtual ~EventSupport(){};


    protected:
      /**
       * 如果返回true，将不再传递此事件，返回false将继续处理此事件
       */
      virtual bool event(const Thk::Event* e) {

        //绘制元素或层
        if (e->getType() == PaintEvent::Type) {
          paintEvent((const PaintEvent*)e);

        //被修改状态
        }else if (e->getType() == ModifiedEvent::Type) {
          modifiedEvent((const ModifiedEvent*)e);

        //鼠标相关
        //鼠标在层上移动
        }else if (e->getType() == MouseEvent::MoveType) {
         mouseMoveEvent((const MouseEvent*)e);

        //鼠标按键
       }else if(e->getType() == MouseEvent::PressType){
         mousePressEvent((const MouseEvent*)e);

         //鼠标放开按键
       }else if(e->getType() == MouseEvent::ReleaseType){
         mouseReleaseEvent((const MouseEvent*)e);

         //鼠标双击层或元素
       }else if(e->getType() == MouseEvent::DoubleClickType){
         mouseDoubleClickEvent((const MouseEvent*)e);

         //鼠标滑轮滚动
       }else if(e->getType() == WheelEvent::Type){
         mouseWheelEvent((const WheelEvent*)e);

         //鼠标离开层或元素
       }else if(e->getType() == MouseEvent::LeaveType){
         mouseLeaveEvent((const MouseEvent*)e);

         //鼠标进入层或元素
       }else if(e->getType() == MouseEvent::EnterType){
         mouseEnterEvent((const MouseEvent*)e);

       //键盘相关
       }else if (e->getType() == KeyEvent::PressType) {
         keyPressEvent((const KeyEvent*)e);

       }else if(e->getType() == KeyEvent::ReleaseType){
         keyReleaseEvent((const KeyEvent*)e);

       //选择元素
       }else if(e->getType() == SelectEvent::Type){
         selectEvent((const SelectEvent*)e);
       }

        //转发事件
        return Thk::EventDispatcher::fire(e);
      }

      /**
       * 当鼠标在层或元素上移动时
       */
      virtual void mouseMoveEvent(const MouseEvent* e) {}
      /**
       * 当鼠标在层或元素上按下按键时
       */
      virtual void mousePressEvent(const MouseEvent* e) {}
      /**
       * 当鼠标在层或元素上释放按键时
       */
      virtual void mouseReleaseEvent(const MouseEvent* e) {}
      /**
       * 当鼠标在层或元素上双击时
       */
      virtual void mouseDoubleClickEvent(const MouseEvent* e){}
      /**
       * 当鼠标从层或元素上移出时
       */
      virtual void mouseLeaveEvent(const MouseEvent* e) {}

      /**
       * 当鼠标进入层或元素上移出时
       */
      virtual void mouseEnterEvent(const MouseEvent* e) {}

      /**
       * 鼠标滑轮事件
       */
      virtual void mouseWheelEvent(const WheelEvent* e) {}
      /**
       * 键被按下
       */
      virtual void keyPressEvent(const KeyEvent* e){}
      /**
       * 键被释放
       */
      virtual void keyReleaseEvent(const KeyEvent* e){}
      /**
       * 选中/取消选择元素事件
       */
      virtual void selectEvent(const SelectEvent* e){}
      /**
       * 当修改被修改状态时
       */
      virtual void modifiedEvent(const ModifiedEvent* e) {}

      /**
       * 绘制层或元素时
       */
      virtual void paintEvent(const PaintEvent* e){};

//      virtual void focusInEvent(FocusEvent *);
//      virtual void focusOutEvent(FocusEvent *);
//      virtual void enterEvent(Event *); OK
//      virtual void leaveEvent(Event *); OK
//      virtual void paintEvent(PaintEvent *); OK

//      virtual void moveEvent(MoveEvent *);
//      virtual void resizeEvent(ResizeEvent *);

//      virtual void closeEvent(CloseEvent *);
//      virtual void showEvent(ShowEvent *);
//      virtual void hideEvent(HideEvent *);


//      virtual void dragEnterEvent(DragEnterEvent *);
//      virtual void dragMoveEvent(DragMoveEvent *);
//      virtual void dragLeaveEvent(DragLeaveEvent *);
//      virtual void dropEvent(DropEvent *);


  };

}

#endif /* DEVENTDISPATCHER_H_ */
